
 function gongshi () {
    var ids = getSelectedRows();
    if (ids == null) {
        return;
    }
    var lock = false;
    layer.confirm('确定要公示选中的记录？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        if (!lock) {
            lock = true;
            $.ajax({
                type: "POST",
                url: baseURL + "sys/tianan/gongshi",
                contentType: "application/json",
                data: JSON.stringify(ids),
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg("操作成功", {icon: 1});
                        $("#jqGrid").trigger("reloadGrid");
                    } else {
                        layer.alert(r.msg);
                    }
                }
            });
        }
    }, function () {
    });
};

 function nogongshi () {
     var ids = getSelectedRows();
     if (ids == null) {
         return;
     }
     var lock = false;
     layer.confirm('确定要取消公示选中的记录？', {
         btn: ['确定', '取消'] //按钮
     }, function () {
         if (!lock) {
             lock = true;
             $.ajax({
                 type: "POST",
                 url: baseURL + "sys/tianan/nogongshi",
                 contentType: "application/json",
                 data: JSON.stringify(ids),
                 success: function (r) {
                     if (r.code == 0) {
                         layer.msg("操作成功", {icon: 1});
                         $("#jqGrid").trigger("reloadGrid");
                     } else {
                         layer.alert(r.msg);
                     }
                 }
             });
         }
     }, function () {
     });
 };


 var downUrl = [];
 var title;
 function infos(id) {
     var tianan;
     $.ajax({
         type: "GET",
         url: baseURL + "../sys/tianan/info/" + id,
         cache: false,
         async: false,
         success: function (r) {
             tianan = r.tianan;
             var lianstatu;
             if (tianan.lianstatus == 2||tianan.lianstatus == '2') {
                 lianstatu = checkstatus(tianan.banjiestatus)
             } else {
                 lianstatu = lianstatus(tianan.lianstatus)

             }
             if(tianan.liantype==3){

                 lianstatu = '<span style="color: red">终止</span>';
             }
             if (tianan.banjiestatus<5) {
                 tianan.subexplain='';
                 tianan.subfile='';

             }

             layer.open({
                 title: tianan.title,
                 type: 1,
                 skin: 'layui-layer-molv',
                 area: ['800px', '450px'],
                 content: '<div class="row" style="padding: 10px">' +
                     ' <table class="table table-bordered table-style"> ' +
                     ' <tbody> ' +
                     '<tr><td style="width:110px; ">提案人</td><td style="    width: 140px;">' + isnull(tianan.creatusername) + '</td><td style="width:85px;text-align: center; ">提案类别</td><td>' + isnull(tianan.typesName) + '</td><td style="width:85px;text-align: center; ">所在部门</td><td>' + isnull(tianan.deptIdName) + '</td></tr>' +
                     '<tr><td>案由分析</td><td colspan="5">' + isnull(tianan.anyoufenxi) + '</td></tr>' +
                     '<tr><td>措施建议</td><td colspan="5">' + isnull(tianan.cuoshijianyi) + '</td></tr>' +
                     '<tr><td>办理时限</td><td >' + isnull(tianan.endtime) + '</td><td style="width:85px;text-align: center;">办理类型</td><td>' + isnull(liantype(tianan.liantype)) + '</td><td style="width:85px;text-align: center; ">办理部门</td><td>' + isnull(tianan.liandeptname) + '</td></tr>' +
                     '<tr><td>提案类型</td><td >' + isnull(tianleibie(tianan.type)) + '</td><td style="width:85px;text-align: center;">办理状态</td><td>' + lianstatu + '</td><td style="width:85px;text-align: center; ">提案人满意度</td><td>' + isnull(manyistatus(tianan.manyi)) + '</td></tr>' +
                     '<tr><td>提案答复</td><td colspan="5">' + isnull(tianan.subexplain) + '</td></tr>' +
                     '<tr><td>部门负责人审核时间</td><td colspan="2">' + isnull(tianan.restime) + '</td><td>分管院领导审核时间</td><td colspan="2">' + isnull(tianan.ledtime) + '</td></tr>' +
                     '<tr><td>签发意见</td><td >' + yijian(tianan.tongyi) + '</td><td>意见</td><td colspan="3">' + isnull(tianan.yijian) + '</td></tr>' +
                     ' </tbody> ' +
                     '</table>' +
                     '<div class="input-group ">相关附件：<ul id="ulli"></ul></div>' +
                     ' </div>',
                 success: function () {

                     if (tianan.subfile != null && tianan.subfile != '') {
                         var s = [];
                         s = tianan.subfile.split(",");
                         //遍历所有文件
                         for (var i = 0; i < s.length; i++) {
                             if (s[i] != null && s[i] != 'null') {
                                 s[i].replace("/", "\\")
                             }
                             var fileNameIndex = s[i].lastIndexOf("\\");
                             var filePathName = s[i].substring(fileNameIndex + 1);
                             var html = filePathName;
                             downUrl.push(s[i]);

                             html = '<li>' +
                                 html + '<a class="operation_type" style="color: #0c74c4; text-decoration:none" href="../../../sys/file/fileDown?fileDir=' + encodeURIComponent(s[i]) + '"  > &nbsp;&nbsp;下载</a>'
                                 + "<a class='operation_type'  style='color: #0c74c4;  border:none;text-decoration:none'   onclick='eye( \"" + s[i].replace(/\\/g, "//") + "\")' href='javascript:;'  > &nbsp;&nbsp;预览</a></li>";
                             $("#ulli").append(html);
                         }
                     } else {
                         $("#ulli").append("<p>无</p>");
                     }
                 }
             })
         }
     })
 }
function init() {

    $("#jqGridtable").html("");
    $("#jqGridtable").html('<table id="jqGrid"></table><div id="jqGridPager"></div>');
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/tianan/listgongshichuli?sea=' + $("#sea").val() + '&types=' + $("#types").val() + '&banjiestatus=' + 6 + '&manyi=' + $("#manyi").val() + '&liandept=' + $("#liandept").val()+ '&gongshi=' + $("#gongshi").val()+ '&year=' +$('#listyear').val(),
        datatype: "json",
        colModel: [
            {label: '提案名称', name: 'title', index: 'title', width: 80},

            {
                label: '提案类型',
                name: 'typesName',
                index: 'typesName',
                align: 'center',
                width: 40,
            },
            {label: '提案人', align: 'center', sortable: true, name: 'creatusername', index: 'dept_id', width: 40},
            {label: '发表时间', name: 'createTime', align: 'center', sortable: true, index: 'createTime', width: 40},
            {label: '办理部门', name: 'deptIdName', align: 'center', sortable: true, index: 'deptIdName', width: 40},
            {
                label: '标签',
                align: 'center',
                sortable: true,
                name: 'lable',
                index: 'lable',
                width: 40,
            },

            {
                label: '签发意见 ',
                align: 'center',
                sortable: true,
                name: 'tongyi',
                index: 'tongyi',
                width: 40,
                formatter: function (value, row, rowObject) {
                 return  yijian(value)

                }

            },
            {
                label: '是否公示', align: 'center', sortable: true, name: 'gongshi', index: 'gongshi', width: 40,

                formatter: function (value, row, rowObject) {
                    if (value=="0") {
                        return "<span style='color: red'> 未公示</span>";
                    } else {
                        return "<span style='color: #00a65a'> 已公示</span>";
                    }

                }
            },
            {
                label: '满意度', name: 'manyi', align: 'center', sortable: true, index: 'manyi', width: 40,
                formatter: function (value, row, rowObject) {

                    return manyistatus(rowObject.manyi);


                }
            },
            {
                label: '操作',
                name: 'id',
                align: 'center',
                index: 'id',
                width: 40,
                formatter: function (value, row, rowObject) {
                    var but = "";
                    but += ' <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="infos(' + value + ')">详情</button>';

                    return but;
                }
            }


        ],
        viewrecords: true,
        height: 450,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
}

$(function () {
    init();
    $('.selectpicker').selectpicker({
        width: '160px'
    });
    $('.selectpicker').selectpicker("");
    var d = new Date();
    // $(".titleyear").html(d.getFullYear() + "提案公示")
    $(".titleyear").html( "提案公示")
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        listyear:inityear(),
        deptlist: getDeptAll(''),
        dictlist: getDict('tiantype'),
        tiananShenyi: {},
        tianan: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.tiananShenyi = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function () {
                var url = vm.tiananShenyi.id == null ? "sys/tiananshenyi/save" : "sys/tiananshenyi/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tiananShenyi),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("操作成功", {icon: 1});
                            vm.reload();
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        } else {
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
            });
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }
            var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                if (!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "sys/tiananshenyi/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function (r) {
                            if (r.code == 0) {
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
            }, function () {
            });
        },
        getInfo: function (id) {
            $.get(baseURL + "sys/tiananshenyi/info/" + id, function (r) {
                vm.tiananShenyi = r.tiananShenyi;
            });
        },
        gettiananInfo: function (id) {

        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    }
});
